#include "logindialog.h"

#include <QApplication>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QMessageBox>

#include <QLocale>
#include <QTranslator>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("users.db");


    if(!db.open()){
        // QMessageBox::Warning(nullptr,"警告","无法创建数据库!");
        qDebug()<<"failed to open db:"<<db.lastError();
        return 0;
    }else{
        qDebug()<<"success to open db";
    }

    QString createsql=QString("CREATE TABLE IF NOT EXISTS users("
                                "id INTEGER PRIMARY KEY AUTOINCREMENT,"
                                "username TEXT NOT NULL,"
                                "password TEXT NOT NULL)");
    QSqlQuery query;
    if(!query.exec(createsql)){
        qDebug()<<"table create error";
    }else{
        qDebug()<<"table create success";
    }
    QTranslator translator;
    const QStringList uiLanguages = QLocale::system().uiLanguages();
    for (const QString &locale : uiLanguages) {
        const QString baseName = "test_project_" + QLocale(locale).name();
        if (translator.load(":/i18n/" + baseName)) {
            a.installTranslator(&translator);
            break;
        }
    }


    Dialog w;
    w.show();
    return a.exec();
}
